package com.ruoyi.project.module.action.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.project.module.action.domain.Action;
import com.ruoyi.project.module.action.service.IActionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 测试 信息操作处理
 *
 * @author ruoyi
 * @date 2018-07-06
 */
@Controller
@RequestMapping("/module/action")
public class ActionController extends BaseController {
    private String prefix = "module/action";

    @Autowired
    private IActionService actionService;

    @RequiresPermissions("module:action:view")
    @GetMapping()
    public String action() {
        return prefix + "/action";
    }

    /**
     * 查询测试列表
     */
    @RequiresPermissions("module:action:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Action action) {
        startPage();
        List<Action> list = actionService.selectActionList(action);
        return getDataTable(list);
    }

    /**
     * 新增测试
     */
    @RequiresPermissions("module:action:add")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 修改测试
     */
    @RequiresPermissions("module:action:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, Model model) {
        Action action = actionService.selectActionById(id);
        model.addAttribute("action", action);
        return prefix + "/edit";
    }

    /**
     * 保存测试
     */
    @RequiresPermissions("module:action:save")
    @PostMapping("/save")
    @ResponseBody
    public AjaxResult save(Action action) {
        if (actionService.saveAction(action) > 0) {
            return success();
        }
        return error();
    }

    /**
     * 删除测试
     */
    @RequiresPermissions("module:action:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int rows = actionService.deleteActionByIds(ids);
        if (rows > 0) {
            return success();
        }
        return error();
    }

}
